package com.controller;
import com.entity.AllUserInfo;
import com.github.pagehelper.PageInfo;
import com.service.AllUserInfoService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (AllUserInfo)表控制层
 *
 * @author makejava
 * @since 2023-06-19 13:43:58
 */
@RestController
@RequestMapping("/allUserInfo")
public class AllUserInfoController {
    /**
     * 服务对象
     */
    @Resource
    private AllUserInfoService allUserInfoService;

    /**
     * 模糊分页查询
     * @param pageNum
     * @param pageSize
     * @return 查询结果
     */
    @GetMapping("/fuzzyQuery/{condition}")
    public ResponseEntity<PageInfo<AllUserInfo>> queryFuzzyPage(@RequestParam(defaultValue = "1") int pageNum,
                                                                @RequestParam(defaultValue = "10") int pageSize
            , @PathVariable("condition") String condition) {
        PageInfo<AllUserInfo> pageInfo = allUserInfoService.fuzzyQuery(pageNum,pageSize,condition);
        return ResponseEntity.ok(pageInfo);
    }

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return 查询结果
     */
    @GetMapping("/byPage")
    public ResponseEntity<PageInfo<AllUserInfo>> queryByPage(@RequestParam(defaultValue = "1") int pageNum,
                                                             @RequestParam(defaultValue = "10") int pageSize) {
        PageInfo<AllUserInfo> pageInfo = allUserInfoService.selectByPage(pageNum, pageSize);
        return ResponseEntity.ok(pageInfo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/id/{id}")
    public ResponseEntity<AllUserInfo> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.allUserInfoService.queryById(id));
    }

}

